/*
ALL INTERMEDIATE HOUSEHOLD OUTCOMES
*/

clear all
set more off
capture log close

 if c(username) == "alison_a" {
        global ROOT "C:\Users\alison_a\Dropbox\HI_shared (1)\"
		global ROOT1 "C:\Users\alison_a\Dropbox\HI_shared\"
    }

if c(username) == "sonya_k" {
        global ROOT "C:\Users\sonya_k\Dropbox\HI_shared\"
		global ROOT1 "C:\Users\sonya_k\Dropbox\HI_private\"
    }
	
if c(username) == "Sonya" {
        global ROOT "C:\Users\Sonya\Dropbox\HI_shared"
		global ROOT1 "C:\Users\Sonya\Dropbox\HI_private\"
    }

if c(username) == "sofyakrutikova" {
        global ROOT "/Users/sofyakrutikova/Dropbox/HI_shared/endline report/"
		global ROOT1 "/Users/sofyakrutikova/Dropbox/HI_private/"
    }

			
global output 				"$ROOT/endline report/draft 2"
global do 					"$ROOT/do-files"
global data_constructed 	"C:\Users\alison_a\Dropbox\HI_shared (1)\endline report\FINAL\DATA"
global rw 					"$ROOT/data/RW/T-value distributions"
		
		
do "$do\stata programs for drawing tables\programs for endline tables, standardisations etc"		

	* load data
use "$data_constructed\child_analysis_data"

	
 tab cc_ent, gen(cc_ent_)
 tab dane, gen(dane_)
 
 * CONTROLS
 ***********
 global controls_child "cc_ent_* dane_* age_days_quest male"
 

/*xvii. Improved routines (reading in particular) in the house ----- NOT IN REPORT
	*******************************/
	
	* FCI - IMPROVED ROUTINES
	**********
	* define labels
	local a1 "Activities with books"
	local b1 "Telling stories"
	local c1 "Singing"
	local d1 "Go to park, sqaure etc"
	local e1 "Go out to do chores"
	local f1 "Go out to play"
	local g1 "Play with child's toys"
	local h1 "Draw, paint etc"
	local i1 "Naming, counting etc"
	local j1 "Talking about day etc"
	local k1 "Watching TV"
	local l1 "Dancing"
	
	* ACTIVITIES WITH MOTHER  
	***************************
	foreach x in a b c d e f g h i j k l {
		rename fci_act_moth_week_`x'_1 fci_act_moth_week_`x'
		label var fci_act_moth_week_`x' "``x'1'"
		gen fci_act_moth_week_`x'_0=(fci_mother_`x'_0>0) if fci_mother_`x'_0~=.
		}

	* create factor
	factor fci_mother*
	predict factor_time_moth
	label var  factor_time_moth "\textbf{Activities with mother (factor)}"
		
	factor fci_mother*_0
	predict factor_time_moth_0
	
	myttests fci_mother_a-fci_mother_l  factor_time_moth, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	set trace off
	table_2s, filename(fci_act_mother)	
	

	* ACTIVITIES WITH FATHER
	************************
	
	* create factor
	factor fci_father*
	predict factor_time_father
	label var  factor_time_father "\textbf{Activities with father (factor)}"
	
	* generate BL measure
	foreach x in a b c d e f g h i j k l {
		gen fci_father_`x'_0 = fci_mother_`x'_0
		}
	gen factor_time_father_0= factor_time_moth_0 
	
	myttests fci_father_a-fci_father_l  factor_time_father, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	set trace off
	table_2s, filename(fci_act_father)	
	

		* ACTIVITIES WITH OTHER
	************************
	* create factor
	factor fci_other*
	predict factor_time_other
	label var  factor_time_other "\textbf{Activities with other HH member (factor)}"
	
	* generate BL measure
	foreach x in a b c d e f g h i j k l {
		gen fci_other_`x'_0 = fci_father_`x'_0
		}
	gen factor_time_other_0= factor_time_father_0 
	
	myttests fci_other_a-fci_other_l  factor_time_other, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	set trace off
	table_2s, filename(fci_act_other)	
	
	
	* TOTAL ACTIVITIES WITH HH MEMBER
	**********************************
	* gen bl
	foreach x in a b c d e f g h i j k l {
		gen fci_total_`x'_0 = fci_other_`x'_0
		}
		
		
	* create factor
	factor fci_total_*
	predict factor_time_total 
	label var  factor_time_total "\textbf{Activities with any HH member (factor)}"
		
	gen  factor_time_total_0=factor_time_other_0 
	
	myttests fci_total_a-fci_total_l  factor_time_total, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	set trace off
	table_2s, filename(fci_act_total)	
	
	
	* ACTIVITIES BY SELF
	*********************

	* create factor
	factor fci_self*
	predict factor_time_self
	label var  factor_time_self "\textbf{Activities by self (factor)}"
	
	* generate BL measure
	foreach x in a  f g h i  k  {
		gen fci_self_`x'_0 = fci_other_`x'_0
		}
	gen factor_time_self_0=  factor_time_total_0 
	
	myttests fci_self_a-fci_self_k  factor_time_self, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	set trace off
	table_2s, filename(fci_act_self)
	
	
	* MATERIALS AT HOME
	********************
	* create factor
	* create factor
	factor fci_mat_a fci_mat_b fci_mat_c
	predict  factor_fci_mat_sources
	label var  factor_fci_mat_sources "Sources of Play materials"

	factor fci_mat_a_0 fci_mat_b_0 fci_mat_c_0
	predict  factor_fci_mat_sources_0
	label var  factor_fci_mat_sources_0 "Sources of Play materials"
	
	factor fci_mat_d-fci_mat_k	
	predict factor_fci_mat_var
	label var  factor_fci_mat_var "Variety of Play materials"
	
	factor fci_mat_d_0-fci_mat_k_0
	predict factor_fci_mat_var_0
	label var  factor_fci_mat_var_0 "Variety of Play materials"
	
	myttests fci_mat_a-fci_mat_k factor_fci_mat_sources factor_fci_mat_var, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	set trace off
	table_2s, filename(fci_mat)

	* SUMMARY FCI TABLE
	*********************
	gen fci_numbooks=read_numbooks
	gen fci_nummags=read_nummags
	gen fci_numbooks_0=read_numbooks_0
	gen fci_nummags_0=read_nummags_0

	* rescale all factors to (0,1) of control group 
	foreach var of varlist factor_fci* factor_time* fci_numbooks fci_nummags {
		sum `var' if itt2==0 & itt3==0
		replace `var'=(`var'-r(mean))/r(sd)
		}
	label var factor_time_moth "Play activities with mother (factor)"
	label var factor_time_father "Play activities with father (factor)"
	label var factor_time_total "Play activities with any HH member (factor)"
	label var factor_time_self "Play activities by self"
	label var factor_fci_mat_var "Variety of play materials (factor)"
	label var factor_fci_mat_sources "Sources of play materials (factor)"
	label var fci_numbooks "Number of adult books in HH (standardised)"
	label var fci_nummags 	"Number of newspapers and magazines in HH (standardised)"
	myttests factor_time_moth factor_time_father  factor_time_total factor_time_self factor_fci_mat_var factor_fci_mat_sources    fci_numbooks fci_nummags  , itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	table_std_2s, filename(fci_summary)
	
	
	* READING AT HOME TABLE
	***********************
	gen read_minsperweek_hh=fci_total_a 
	label var read_minsperweek_hh "Minutes per week looking at/reading books with HH member"
	gen read_minsperweek_self=fci_self_a 
	label var read_minsperweek_self "Minutes per week looking at/reading books by self"
	
	gen read_numchildrens_0= read_numbooks
	gen read_minsperweek_hh_0=fci_total_a_0
	gen read_minsperweek_self_0=fci_total_a_0
	
	myttests  read_numchildrens  read_minsperweek_hh read_minsperweek_self, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) bl(y)
	table_2s, filename(reading_in_home)
	
	label var  read_bought  "Bought books for child to read in last 6 months"
	label var read_borrow "Bollowed books for child to read since Jan 2013"
	
	recode read_borrow_0 read_borrow read_enough read_childenough read_enough_0 read_childenough_0 (2=0)
	gen read_bought_0=read_borrow_0
	myttests_bin read_bought  read_borrow , itt2(itt2) itt3(itt3) cluster(ll_inst) controls($controls_child) bl(y)
	table_bin_2s, filename(reading_in_home_bin)

	
		
	* DESCRIPTIVES OF nursery SCHOOL ATTENDANCE
	*******************************************
	* whether still attends bl nursery -  m3_301
	label var  m3_301 "Child still attends BL nursery"

	set trace off	
	myttests_bin  m3_301, itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child)
	table_bin_2s, filename(attends_nursery)
	
	myttests nurs* , itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) 
	table_2s, filename(nursery_attendance)
	
	egen nurs_total=rowtotal(nurs_mth_2013  nurs_mth_2014)
	label var nurs_total "nursery attendance (mths in 2013 and 2014)"
	
	myttests_process m3_301 nurs_*, itt2(itt2) itt3(itt3) 
	table_process2, filename(nursery_attendance)

	
	* nursery SERVICE PERCEPTION AND ENGAGEMENT
	*******************************************
	myttests nursery_perception nursery_engagement , bl(y)  itt2(itt2) itt3(itt3) cluster(ll_inst ) controls($controls_child) 
	table_std_2s, filename(nursery_scales)
	
	* DIETARY MEASURES
	*******************
	myttests food_*_num , itt2(itt2) itt3(itt3) bl(y) cluster(ll_inst ) controls($controls_child) 
	table_2s, filename(foodgroups)
	
	* dietary diversity
	* 1 score - sum all foodgroups (not inc other) that have consumed more than 7 or more of in last 7 days
	* another - sum all those that have consumed more than 3
	
	foreach x in cereal root veg grains fruits meat dairy fats {
		gen mt7_`x'=(food_`x'_num>=7 & food_`x'_num~=.)
		replace mt7_`x'=. if food_`x'_num==.
		gen mt3_`x'=(food_`x'_num>=3 & food_`x'_num~=.)
		replace mt3_`x'=. if food_`x'_num==.
		}
	egen diet_div_7=rowtotal(mt7_*)	, missing
	egen diet_div_3=rowtotal(mt3_*)	, missing

	foreach x in cereal root veg grains fruits meat dairy fats {
		gen mt7_`x'_0=(food_`x'_num_0>=7 & food_`x'_num_0~=.)
		replace mt7_`x'_0=. if food_`x'_num_0==.
		gen mt3_`x'_0=(food_`x'_num_0>=3 & food_`x'_num_0~=.)
		replace mt3_`x'_0=. if food_`x'_num_0==.

		}
	egen diet_div_7_0=rowtotal(mt7_*_0)	, missing
	egen diet_div_3_0=rowtotal(mt3_*_0)	, missing
	
	label var diet_div_7 "Diet diversity scale 1"
	label var diet_div_3 "Diet diversity scale 2"
	
	myttests diet_div_3 diet_div_7 , itt2(itt2) itt3(itt3) bl(y) cluster(ll_inst ) controls($controls_child) 
	table_2s, filename(diet_diversity)
		
	
	
	
